package com.aboo.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	private static String dateParttern = "yyyy-MM-dd";
	private static String timeParttern = "HH:mm:ss";
	
	public static final String getDateString(Date date) {
		String result = "";
		SimpleDateFormat df;		
		if (date != null) {
			df = new SimpleDateFormat(dateParttern);
			result = df.format(date);
		}
		
		return result;
	}
	
	public static final String getDateString(Date date, String datePattern) {
		String result = "";
		SimpleDateFormat df;		
		if (date != null && datePattern != null) {
			df = new SimpleDateFormat(datePattern);
			result = df.format(date);
		}
		return result;
	}
	
	public static final Date getDate(String dateString, String datePattern) {
		Date result = null;
		SimpleDateFormat df;
		if (dateString != null && datePattern != null) {
			try {
				df = new SimpleDateFormat(datePattern);
				result = df.parse(dateString);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public static final String getTimeString(Date date) {
		String result = "";
		SimpleDateFormat df;		
		if (date != null) {
			df = new SimpleDateFormat(timeParttern);
			result = df.format(date);
		}
		
		return result;
	}
	
	public static final String getTimeString(Date date, String timePattern) {
		String result = "";
		SimpleDateFormat df;		
		if (date != null && timePattern != null) {
			df = new SimpleDateFormat(timePattern);
			result = df.format(date);
		}
		return result;
	}
	
	public static final Date getDate(int year, int month, int date) {
		Date result = null;
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		result = cal.getTime();
		return result;
	}
	
	public static final Date getDate(int year, int month, int date, int hour, int minute, int second) {
		Date result = null;
		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date, hour, minute, second);
		result = cal.getTime();
		return result;
	}
	
	public static String getDateParttern() {
		return dateParttern;
	}
	public static void setDateParttern(String dateParttern) {
		DateUtil.dateParttern = dateParttern;
	}
	public static String getTimeParttern() {
		return timeParttern;
	}
	public static void setTimeParttern(String timeParttern) {
		DateUtil.timeParttern = timeParttern;
	}
	
}
